import json
import requests
import random
import time
url = "https://mt.fjii.com/api/wechatShareTask/shareSum"
# 获取从键盘输入的值赋值给userId和token
with open('token.json', 'r') as f:
    userInfo = json.load(f)
print(userInfo)
userId = userInfo['id']
token = userInfo['token']
# userId = input("请输入userId：")
print(userId)
# token = input('请输入token:')
print(token)

# token  = "074fc07a-279a-4ebb-b5e5-54c01533457e"
# userId = 1684743956111429632
# payload="{\"isLoadTip\":\"...\",\"user_id\":\"1316927879329746944\",\"wechat_share_task_id\":\"1414761988562751488\",\"type\":2,\"token_header\":\"xOjqTc9vix%2FIQVwVMZmkpCwp4B2WafoeT991Rnx%2FJhmYF6H9Xv46EkHqmsU%2BjVVIZyeIygoJ8sDqdM7d4AfPy19p0ULjujQFFQMUEzFwNVRNw%2FJo8ou6CGPkfB%2B%2FLMlgX2y%2BudFF9SrsZ5kWvffVJg%3D%3D\"}"
headers = {
    'POSThttps': '//mt.fjii.com/api/wechatShareTask/shareSumHTTP/1.1',
    'Host': 'mt.fjii.com',
    'Connection': 'keep-alive',
    'Content-Length': '302',
    'Accept': 'application/json,text/plain,*/*',
    'User-Agent': 'Mozilla/5.0(Linux;Android10;ALP-AL00Build/HUAWEIALP-AL00;wv)AppleWebKit/537.36(KHTML,likeGecko)Version/4.0 Chrome/124.0.6367.54MobileSafari/537.36wpsystem',
    'Content-Type': 'application/json;charset=UTF-8',
    'sec-ch-ua-platform': "Android",
    'Origin': 'https://mt.fjii.com',
    'X-Requested-With': 'com.fuzhou.wpsystem',
    'Sec-Fetch-Site': 'same-origin',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Dest': 'empty',
    'Accept-Encoding': 'gzip,deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
    'Cookie': f'token={token}'
}
# 从ids.json文件中读取id
with open('ids.json', 'r') as f:
    ids = json.load(f)

# payload="{\"isLoadTip\":\"...\",\"user_id\":\"1684743956111429632\",\"wechat_share_task_id\":\""
payload = "{\"isLoadTip\":\"...\",\"user_id\":" + \
    f"{userId}"+",\"wechat_share_task_id\":\""



#
count = 0
for i in range(1, len(ids)):
    end = "\",\"type\":1,\"appVersion\":\"2.9.13\"}"
    count += 1
    # end="\",\"type\":1,\"token_header\":\"xOjqTc9vix%2FIQVwVMZmkpCwp4B2WafoeT991Rnx%2FJhmYF6H9Xv46EkHqmsU%2BjVVIZyeIygoJ8sDqdM7d4AfPy19p0ULjujQFFQMUEzFwNVRNw%2FJo8ou6CGPkfB%2B%2FLMlgX2y%2BudFF9SrsZ5kWvffVJg%3D%3D\"}"
    payloads = payload+ids[i]+end
    # print(payloads)
    try:
        response = requests.request("POST", url, headers=headers, data=payloads)
    except Exception as error:
        #抓取异常信息，存储到log.txt文件中
        with open('anti-bully-version-log.txt', 'a') as f:
            f.write(f"{error}\n")
        print("出现错误，程序终止")
        break
    print(response.text)
    res_text = response.text
    if res_text.find("分享成功") == -1:
        if res_text.find("成功") != -1:
            with open('anti-bully-version-log.txt', 'a') as f:
                f.write(f"{res_text}token过期\n")
            print("token过期")
            break
        if res_text.find("频繁分享") != -1:
            print("频繁分享，程序休眠10分钟")
            # 休眠601秒并显示倒计时
            for j in range(1, 601):
                print(f"程序将在{601-j}秒后继续执行")
                time.sleep(1)
        else:
            #抓取异常信息
            with open('anti-bully-version-log.txt', 'a') as f:
                f.write(f"{res_text}程序错误，终止执行\n")
            break
    sleep_time = random.randint(20, 30)
    print('休眠了:'+str(sleep_time))
    time.sleep(sleep_time)

print("刷分结束")

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
from email.mime.text import MIMEText

# 邮件发送方和接收方信息
sender = 'asdfzxcvqwer123a@126.com'
receiver1 = 'superces@126.com'
password = 'HRBRRZQTAXWIKKHM'  # 126邮箱的SMTP服务密码
smtpserver = 'smtp.126.com'

# 创建一个带附件的邮件消息对象
msg = MIMEMultipart()
msg['From'] = sender
msg['Subject'] = "招标数据"

# 邮件正文内容
body = "招标数据详见附件"
msg.attach(MIMEText(body, 'plain'))


try:
    smtp = smtplib.SMTP()
    smtp.connect(smtpserver, 25)  # 连接SMTP服务器，25为SMTP端口号
    smtp.login(sender, password)  # 登录邮箱，注意这里是SMTP服务密码
    smtp.sendmail(sender, receiver1, msg.as_string())  # 发送邮件
    # smtp.sendmail(sender, receiver2, msg.as_string())  # 发送邮件
    smtp.quit()
    print("邮件发送成功！")
except smtplib.SMTPException as e:
    print("Error: 无法发送邮件", e)
